package com.cy.deepseeksport.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cy.deepseeksport.domain.ScheduleResult;
import com.cy.deepseeksport.mapper.ScheduleResultMapper;
import com.cy.deepseeksport.service.EmbeddingService;
import dev.langchain4j.store.embedding.EmbeddingStore;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@RestController
public class MatchEmbeddingController {


    @Resource
    private ScheduleResultMapper scheduleResultMapper;

    @Resource
    private EmbeddingService embeddingService;


    @RequestMapping("embeddingzhongchao")
    public String embeddingzhongchao() throws IOException {

        QueryWrapper<ScheduleResult> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("league_id", "60");

        for (ScheduleResult scheduleResult : scheduleResultMapper.selectList(queryWrapper)) {

            Integer matchId = scheduleResult.getMatchId();
            String awayTeamName = scheduleResult.getAwayTeamNameSimplified();
            String homeTeamName = scheduleResult.getHomeTeamNameSimplified();
            Date matchTime = scheduleResult.getMatchTime();


            // === 新增预处理步骤 ===
            // 1. 生成标准化文本描述（供语义检索使用）
            String matchDescription = String.format("%s %s vs %s at %s",
                    DateFormatUtils.format(matchTime, "yyyy-MM-dd HH:mm"),
                    homeTeamName,
                    awayTeamName,
                    scheduleResult.getLeagueNameSimplified()
            );

            embeddingService.processDocument(matchDescription, matchId);


        }

        return "ok";


    }




}
